<?php
namespace Home\Model;
use Think\Model;
class MerchantModel extends Model {
	public function GetOne(){
		$merchant_id = I('get.merchant_id',29);
		$where       = array('merchant_id'=>$merchant_id);
		$data        = $this
		->where($where)
		->find();
		$link        = M('MerchantComment');
		$comment     = $link
		->join('LEFT JOIN ecs_users ON manage_merchant_comment.user_id = ecs_users.user_id ')
		->where($where)
		->limit(20)
		->select();
		$arr          = $this->each($comment);
		$count        = $this->number($merchant_id);
		$data['comment'] = $arr;
		$data['count']   = $count;
		return $data;
	}

	public function each($arr){
		$link        = M('MerchantCommentPhoto');
		foreach($arr as $key =>$val){
			$data = $link
			->where("comment_id = {$val['comment_id']}")
			->select();
			$arr[$key]['photoList'] = $data;

		}
		return $arr;
	}

	public function number($merchant_id){
		$where = array('merchant_id'=>$merchant_id);
		$count = M('MerchantComment')->where($where)->count();
		return $count;
	}
}